macro 'Random Ovals';
var
  PicWidth,PicHeight,hloc,vloc,width,height:real;
begin
  SaveState;
  SetPalette('Spectrum');
  MakeNewWindow('Random Ovals');
  GetPicSize(PicWidth,PicHeight);
  repeat
    hloc:=width*random;
    vloc:=height*random;
    width:=(PicWidth-hloc)*random;
    height:=(PicHeight-vloc)*random;
    MakeOvalRoi(hloc,vloc,width,height);
    SetForeground(255*random);
    fill;
  until Button;
  KillRoi;
  RestoreState;
end;


macro 'Draw Ball';
var
  width,height,n,i,color,diam,nSteps:integer;
begin
  SaveState;
  nSteps:=64;
  SetPalette('Spectrum');
  SetBackground(255); {Black}
  MakeNewWindow('Ball');
  GetPicSize(Width,Height);
  if width>height
    then diam:=height
    else diam:=width;
  color:=1;
  MakeOvalRoi((width-diam)/2,(height-diam)/2,diam,diam);
  for i:=1 to nSteps do begin
    InsetRoi(round(diam/(3*nSteps)));
    SetForeground(color);
    fill;
    color:=color+round(256/nSteps);
    if color>254 then color:=254;
  end;
  KillRoi;
  RestoreState;
end;


macro 'Speckle Paint [S]';
var
  x,y,ranx,rany,MaxSpeckSize,size,Spread:integer;
begin
  RequiresVersion(1.48);
  SetCursor('Cross');
  Spread:=50;
  MaxSpeckSize:=5;
  KillRoi;
  repeat
    GetMouse(x,y);
    if button then begin
      ranx:=x+Spread*(Random-0.5);
      rany:=y+Spread*(Random-0.5);
      size:=(MaxSpeckSize-2)*random+2;
      MakeOvalRoi(ranx-size,rany-size,size*2,size*2);
      SetForeground(Random*254+1);
      fill;
    end;
  until (x<0) or (y<0);
  KillRoi;
end;


macro 'Random Color Boxes';
var
  n,PicWidth,PicHeight,hloc,vloc,size:integer;
begin
  SaveState;
  n:=24;
  GetPicSize(PicWidth,PicHeight);
  if PicWidth=0 then begin
    PutMessage
    ('This macro needs an opened image, preferably in color, to operate on.');
    Exit;
  end;
  size:=round(PicWidth/n);
  repeat
    hloc:=((PicWidth*random) div size)*size;
    vloc:=((PicHeight*random) div size)*size;
    MakeRoi(hloc,vloc,size,size);
    SetForeground(255*random);
    fill;
    {Invert;}
  until Button;
  KillRoi;
  RestoreState;
end;


macro 'Random LUT Colors [C]';
var
  i,colors,entries,first,last,r,g,b:integer;
begin
  RequiresVersion(1.48);
  SetCursor('Watch');
  colors:=25;
  entries:=256/colors;
  if entries>256 then entries:=256;
  repeat 
    first:=random*255;
    last:=first+entries-1;
    if last>255 then last:=255;
    r:=random*255;
    g:=random*255;
    b:=random*255;
    for i:=first to last do begin
      RedLUT[i]:=r;
      GreenLUT[i]:=g;
      BlueLUT[i]:=b;
    end;
    UpdateLUT;
  until button;
end;





